using NHibernate.Mapping.Attributes;

namespace Bussiness.Model
{
    [Class(Name = "Bussiness.Model.User, Bussiness")]
    public class User : BaseModel
    {
        private string _fullName;
        private string _password;
        private string _username;
        private string _email;
        private string _phoneNumber;

        #region Constructors
        /// <summary>
        /// No-args constructor for tools.
        /// </summary>
        public User() { }

        /// <summary>
        /// Simple construtor.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="fullName"></param>
        public User(string username, string password, string fullName)
        {
            _username = username;
            _password = password;
            _fullName = fullName;
        }

        /// <summary>
        /// Full constuctor.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="fullName"></param>
        /// <param name="email"></param>
        /// <param name="phoneNumber"></param>
        public User(string username, string password, string fullName, string email, string phoneNumber)
        {
            _username = username;
            _password = password;
            _fullName = fullName;
            _email = email;
            _phoneNumber = phoneNumber;
        } 
        #endregion

        #region Properties
        [Property(NotNull = true, Length = 100, Unique = true)]
        public virtual string UserName
        {
            get { return _username; }
            set { _username = value; }
        }

        [Property(NotNull = true, Length = 100)]
        public virtual string PassWord
        {
            get { return _password; }
            set { _password = value; }
        }

        [Property(NotNull = true, Length = 150)]
        public virtual string FullName
        {
            get { return _fullName; }
            set { _fullName = value; }
        }

        [Property]
        public virtual string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        [Property]
        public virtual string PhoneNumber
        {
            get { return _phoneNumber; }
            set { _phoneNumber = value; }
        } 
        #endregion

        #region Common methods
        public override bool Equals(object obj)
        {
            if (this == obj) return true;
            if (!(obj is User)) return false;
            var that = (User)obj;
            if (this.FullName != that.FullName) return false;
            if (this.UserName != that.UserName) return false;
            if (this.Email != null ? this.Email != that.Email : that.Email != null) return false;

            return true;
        }

        public override int GetHashCode()
        {
            int result;
            result = UserName.GetHashCode();
            result = 29 * result + FullName.GetHashCode();
            if (Email != null) result = 29 * result + Email.GetHashCode();
            return result;
        } 
        #endregion
    }
}
